package com.zzchangfu.config;

import com.zzchangfu.service.ExpressService;
import com.zzchangfu.service.TimeService;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @program: spring-ai
 * @description:
 * @author: liuChangFu
 * @data: 2025-05-12 14:49
 **/
@Configuration
public class McpConfig {
    @Bean
    public ToolCallbackProvider toolProvider(ExpressService expressService
            , TimeService timeService) {

        MethodToolCallbackProvider provider = MethodToolCallbackProvider.builder()
                .toolObjects(expressService, timeService)
                .build();
        for (ToolCallback callback : provider.getToolCallbacks()) {
            System.out.println("✅ 注册的 Tool: " + callback.getToolDefinition().name());
        }
        return provider;
    }

    @Bean
    public ChatClient chatClient(ChatModel chatModel,ToolCallbackProvider toolProvider) {
        return ChatClient.builder(chatModel)
                .defaultAdvisors(new SimpleLoggerAdvisor())
                .defaultToolCallbacks(toolProvider)
                .build();
    }
}
